package priv.lhy.eureka.client.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * @author: lihy
 * date: 2019/9/10 10:54
 * description:
 */
@RestController
public class DemoController {

    @Autowired
    private DiscoveryClient client;

    @RequestMapping("/hello")
    public String hello(){
        try {
            int sleepTime = new Random().nextInt(3000);
            System.out.println("sleep: " + sleepTime);
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("services:" + client.getServices());
        return "services:" + client.getServices();
    }
}
